// 添加键盘控制
import { LEFT_KEYCODE, RIGHT_KEYCODE } from "./constants.js";



const keyboard = {
  bindEvent(slider) {
    document.addEventListener(
      "keyup",
      (ev) => {
        if (ev.keyCode === LEFT_KEYCODE) {
          slider.prev();

          slider.idx--;

          if (slider.idx === -1) {
            slider.idx = 4;
          }
    
    
          slider.setCircles();

        } else if (ev.keyCode === RIGHT_KEYCODE) {
          slider.next();

          slider.setCircles();


          slider.idx++;
    
          slider.setCircles();
        }
      },
      false
    );
  },
};

export default keyboard;
